package hk.m4s.lr.repair.test.ui;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import framework.common.Constant;
import framework.common.alertview.AlertView;
import framework.common.alertview.OnItemClickListener;
import framework.common.zanetwork.core.ResponseCallback;
import framework.common.zbar.CaptureActivity;
import framework.utils.NetWorkUtil;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.UeApp;
import hk.m4s.lr.repair.test.model.AccountModel;
import hk.m4s.lr.repair.test.model.LatModel;
import hk.m4s.lr.repair.test.model.LatModelResult;
import hk.m4s.lr.repair.test.model.NewsTableModel;
import hk.m4s.lr.repair.test.model.TableModle;
import hk.m4s.lr.repair.test.service.AccountSerive;
import hk.m4s.lr.repair.test.ui.adapter.HorizontalListViewAdapters;
import hk.m4s.lr.repair.test.ui.baoyang.DeviceMainTainActivity;
import hk.m4s.lr.repair.test.ui.baoyang.SqcanDeviceBaoActivity;
import hk.m4s.lr.repair.test.ui.equipment.DeviceRepairActivity;
import hk.m4s.lr.repair.test.ui.user.MyToolkitActivity;
import hk.m4s.lr.repair.test.ui.user.ToolkitActivity;
import hk.m4s.lr.repair.test.utils.CustomDialog;
import hk.m4s.lr.repair.test.utils.CustomerAlertDialog;
import hk.m4s.lr.repair.test.utils.LocationCallBack;
import hk.m4s.lr.repair.test.utils.LocationUtils;
import hk.m4s.lr.repair.test.utils.ShareUtil;
import hk.m4s.lr.repair.test.utils.SharedPreferencesUtil;
import hk.m4s.lr.repair.test.utils.ToastUtil;
import hk.m4s.lr.repair.test.views.HorizontalListView;
import okhttp3.Response;

/**
 * Created by qi.wang on 2017/3/13.
 */

public class HomeFragment extends Fragment implements View.OnClickListener, AMap.OnMarkerClickListener, AMap.InfoWindowAdapter, LocationCallBack {
    private Context context;
    private LayoutInflater inflater;
    private MarkerOptions markerOption;
    MyLocationStyle myLocationStyle;
    private AMapLocationClient mlocationClient;
    private LocationSource.OnLocationChangedListener mListener;
    private UiSettings mUiSettings;
    private AMapLocationClientOption mLocationOption;
    private LinearLayout two_ly;
    private ImageView qr_scan;
    HorizontalListView horizontalListView;
    HorizontalListViewAdapters horizontalListViewAdapter;
    private AMap aMap;
    private MapView mapView;
    private LatLng latlng;
    private TextView equipment_helth, equipment_maintenance, second_hand, tookit, repairBtn;
    private List<TableModle> tabIndicators;
    /**
     * 需要进行检测的权限数组
     */
    protected String[] needPermissions = {
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE
    };

    private static final int PERMISSON_REQUESTCODE = 0;

    /**
     * 判断是否需要检测，防止不停的弹框
     */
    private boolean isNeedCheck = true;
    List<LatModel> latModelList = new ArrayList<>();

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.home_fragment_layout, container, false);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mapView = (MapView) this.getActivity().findViewById(R.id.map);
        mapView.onCreate(savedInstanceState); // 此方法必须重写
        initView();

    }

    private void initView() {
        // TODO Auto-generated method stub
        context = getActivity();
        inflater = LayoutInflater.from(context);
        LocationUtils.getInstance().initLocation(getActivity(), this);
        LocationUtils.getInstance().startLocation();
        findBaseView();
    }

    private void findBaseView() {
        qr_scan = (ImageView) this.getActivity().findViewById(R.id.qr_scan);
        horizontalListView = (HorizontalListView) this.getActivity().findViewById(R.id.daysHorizontalListView);
        equipment_helth = (TextView) this.getActivity().findViewById(R.id.equipment_helth);
        equipment_maintenance = (TextView) this.getActivity().findViewById(R.id.equipment_maintenance);
        second_hand = (TextView) this.getActivity().findViewById(R.id.second_hand);
        tookit = (TextView) this.getActivity().findViewById(R.id.tookit);
        repairBtn = (TextView) this.getActivity().findViewById(R.id.repairBtn);
        two_ly = (LinearLayout) this.getActivity().findViewById(R.id.two_ly);
        equipment_helth.setOnClickListener(this);
        equipment_maintenance.setOnClickListener(this);
        second_hand.setOnClickListener(this);
        tookit.setOnClickListener(this);
        repairBtn.setOnClickListener(this);
        qr_scan.setOnClickListener(this);
        initContent();
        init();


    }

    private void initContent() {
        tabIndicators = new ArrayList<TableModle>();
        if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("2")) {
            TableModle tab1 = new TableModle();
            tab1.setName("发布保养");
            tab1.setId("1");
            tab1.setImages(R.drawable.selector_equipment_helth_btn);
            tabIndicators.add(tab1);
            TableModle tab2 = new TableModle();
            tab2.setName("发布维修");
            tab2.setId("2");
            tab2.setImages(R.drawable.selector_equipment_maintenance_btn);
            tabIndicators.add(tab2);
            TableModle tab4 = new TableModle();
            tab4.setName("工具箱");
            tab4.setId("4");
            tab4.setImages(R.drawable.selector_tookit_btn);
            tabIndicators.add(tab4);
            TableModle tab3 = new TableModle();
            tab3.setName("二手设备");
            tab3.setId("3");
            tab3.setImages(R.drawable.selector_second_hand_btn);
            tabIndicators.add(tab3);
        } else if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("3")) {
            TableModle tab3 = new TableModle();
            tab3.setName("二手设备");
            tab3.setId("3");
            tab3.setImages(R.drawable.selector_second_hand_btn);
            tabIndicators.add(tab3);
            TableModle tab4 = new TableModle();
            tab4.setName("工具箱");
            tab4.setId("4");
            tab4.setImages(R.drawable.selector_tookit_btn);
            tabIndicators.add(tab4);
            TableModle tab5 = new TableModle();
            tab5.setName("一键报修");
            tab5.setId("5");
            tab5.setImages(R.drawable.selector_repaire_btn);
            tabIndicators.add(tab5);
        } else {
            TableModle tab3 = new TableModle();
            tab3.setName("二手设备");
            tab3.setId("3");
            tab3.setImages(R.drawable.selector_second_hand_btn);
            tabIndicators.add(tab3);
        }
        if (tabIndicators.size() > 4) {
            two_ly.setVisibility(View.GONE);
            horizontalListView.setVisibility(View.VISIBLE);
            horizontalListViewAdapter = new HorizontalListViewAdapters(getActivity(), tabIndicators);
            horizontalListView.setAdapter(horizontalListViewAdapter);
            horizontalListView.setOnItemClickListener(clickItem);
        } else {
            two_ly.setVisibility(View.VISIBLE);
            if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("2")) {
                equipment_helth.setVisibility(View.VISIBLE);
                equipment_maintenance.setVisibility(View.VISIBLE);
                tookit.setVisibility(View.VISIBLE);
                repairBtn.setVisibility(View.GONE);
                second_hand.setVisibility(View.VISIBLE);
            } else if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("3")) {
                equipment_helth.setVisibility(View.GONE);
                equipment_maintenance.setVisibility(View.GONE);
                tookit.setVisibility(View.VISIBLE);
                repairBtn.setVisibility(View.VISIBLE);
                second_hand.setVisibility(View.VISIBLE);
            } else {
                equipment_helth.setVisibility(View.GONE);
                equipment_maintenance.setVisibility(View.GONE);
                tookit.setVisibility(View.GONE);
                repairBtn.setVisibility(View.GONE);
                second_hand.setVisibility(View.VISIBLE);
            }
            horizontalListView.setVisibility(View.GONE);
        }
    }

    void init() {
        if (aMap == null) {
            aMap = mapView.getMap();
            mUiSettings = aMap.getUiSettings();
            //地图模式可选类型：MAP_TYPE_NORMAL,MAP_TYPE_SATELLITE,MAP_TYPE_NIGHT
            aMap.setMapType(AMap.MAP_TYPE_NORMAL);
            setUpMap();
        }
    }

    /**
     * 设置一些amap的属性
     */
    private void setUpMap() {
        aMap.setOnMarkerClickListener(this);
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        aMap.setInfoWindowAdapter(this);
        mUiSettings.setMyLocationButtonEnabled(false); // 是否显示默认的定位按钮
        aMap.setMyLocationEnabled(true);
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE);//定位一次，且将视角移动到地图中心点。
        myLocationStyle.radiusFillColor(android.R.color.transparent);
        myLocationStyle.strokeColor(android.R.color.transparent);
        aMap.setMyLocationStyle(myLocationStyle);
        // 设置定位的类型为定位模式 ，可以由定位、跟随或地图根据面向方向旋转几种
        aMap.setMyLocationType(AMap.LOCATION_TYPE_MAP_FOLLOW);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.qr_scan:
                if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                    ToastUtil.toast(context, "非企业用户不能使用");
                } else {
                    getActivity().startActivity(new Intent(getActivity(), CaptureActivity.class).putExtra("type", "1"));
                }
                break;
            case R.id.equipment_helth:
                if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                    ToastUtil.toast(context, "非企业用户不能使用");
                } else {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE)
                            != PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(getActivity(), "没有权限,请手动开启定位权限", Toast.LENGTH_SHORT).show();
                        // 申请一个（或多个）权限，并提供用于回调返回的获取码（用户定义）

                    } else {
                        getActivity().startActivity(new Intent(getActivity(), DeviceMainTainActivity.class));
                    }

                }
                break;
            case R.id.equipment_maintenance:
                if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                    ToastUtil.toast(context, "非企业用户不能使用");
                } else {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE)
                            != PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(getActivity(), "没有权限,请手动开启定位权限", Toast.LENGTH_SHORT).show();
                        // 申请一个（或多个）权限，并提供用于回调返回的获取码（用户定义）

                    } else {
                        getActivity().startActivity(new Intent(getActivity(), DeviceRepairActivity.class));
                    }
                }
                break;
            case R.id.second_hand:
                break;
            case R.id.tookit:
                if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                    ToastUtil.toast(context, "非企业用户不能使用");
                } else {
                    Intent ktiIntent = null;
                    if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("2")) {
                        ktiIntent = new Intent(getActivity(), MyToolkitActivity.class);
                    } else {
                        ktiIntent = new Intent(getActivity(), ToolkitActivity.class);
                    }
                    ktiIntent.putExtra("type", "1");
                    ktiIntent.putExtra("title", "" +
                            "工具箱");
                    startActivity(ktiIntent);
                }
                break;
            case R.id.repairBtn:
                if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                    ToastUtil.toast(context, "非企业用户不能使用");
                } else {
                    getActivity().startActivity(new Intent(getActivity(), CaptureActivity.class).putExtra("type", "2"));
                }
                break;
        }
    }

    /**
     * 方法必须重写
     */
    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();

    }

    /**
     * 方法必须重写
     */
    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    /**
     * 方法必须重写
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    public void agency(String province, String city) {

// POST 参数
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            JSONObject jsondata = new JSONObject();
            params.put("device_type", Constant.device_type);
            params.put("token", SharedPreferencesUtils.getSharedPreferences(Constant.token, ""));
            jsondata.put("province", province);
            jsondata.put("city", city);
            params.put("jsonText", jsondata.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        AccountSerive.agency(getActivity(), params, new ResponseCallback<LatModelResult>() {
            @Override
            public void onSuccess(LatModelResult map) {
                latModelList.clear();
                if (map.getList() != null) {
                    latModelList = map.getList();
                    for (int i = 0; i < latModelList.size(); i++) {
                        LatModel model = latModelList.get(i);
                        if (model.getLat() != null && model.getLng() != null) {
                            LatLng latLng = new LatLng(Double.parseDouble(model.getLat()), Double.parseDouble(model.getLng()));

                            aMap.addMarker(new MarkerOptions().position(latLng).title(model.getName()).icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
                                    .decodeResource(getResources(), R.mipmap.gps_point)))).setObject(model);
                        }
                    }
                }
            }

            @Override
            public void onError(Response response, int errorCode, String errorMsg, Exception e) {

            }
        });
    }

    /**
     * 对marker标注点点击响应事件
     */
    @Override
    public boolean onMarkerClick(final Marker marker) {

        return false;
    }

    /* 监听自定义infowindow窗口的infowindow事件回调
    */
    @Override
    public View getInfoWindow(Marker marker) {
        View infoWindow = getActivity().getLayoutInflater().inflate(
                R.layout.custom_info_window, null);
        final LatModel model = (LatModel) marker.getObject();
        TextView title = (TextView) infoWindow.findViewById(R.id.map_popup_name);
        TextView tel = (TextView) infoWindow.findViewById(R.id.map_popup_phone);
        TextView custom = (TextView) infoWindow.findViewById(R.id.map_popup_dial);
        TextView map_popup_km = (TextView) infoWindow.findViewById(R.id.map_popup_km);
        float distance = AMapUtils.calculateLineDistance(marker.getPosition(), latlng);
        title.setText(model.getName());
        tel.setText(model.getContactPhone());
        custom.setText(model.getContact());
        if (distance < 1000) {
            map_popup_km.setText(String.format("%.2f", distance) + "m");
        } else {
            map_popup_km.setText((String.format("%.2f", distance / 1000)) + "Km");
        }
        tel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!(model.getContactPhone() == null || model.getContactPhone().equals(""))) {
                    if (ContextCompat.checkSelfPermission(((Activity) context),
                            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                        // 没有获得授权，申请授权
                        if (ActivityCompat.shouldShowRequestPermissionRationale(((Activity) context),
                                Manifest.permission.CALL_PHONE)) {
                            // 返回值：
//                          如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.
//                          如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.
//                          如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
                            // 弹窗需要解释为何需要该权限，再次请求授权
                            // 帮跳转到该应用的设置界面，让用户手动授权
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", context.getPackageName(), null);
                            intent.setData(uri);
                            context.startActivity(intent);
                        } else {
                            // 不需要解释为何需要该权限，直接请求授权
                            ActivityCompat.requestPermissions(((Activity) context),
                                    new String[]{Manifest.permission.CALL_PHONE},
                                    1);
                        }
                    } else {
                        Intent phoneIntent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + model.getContactPhone()));
                        context.startActivity(phoneIntent);
                    }
                } else {
                    ToastUtil.toast(context, "电话不正确");
                }
            }
        });
        return infoWindow;
    }

    /**
     * 监听自定义infowindow窗口的infocontents事件回调
     */
    @Override
    public View getInfoContents(Marker marker) {

        return null;
    }

    @Override
    public void AMapLocationListenerCallBack(AMapLocation location) {
        Log.e("经纬度>>>", location.getLatitude() + ">>>>" + location.getLongitude() + "省>>>" + location.getProvince() + "市>>>" + location.getCity() + "区>>" + location.getDistrict());
        SharedPreferencesUtils.addgetSharedPreferences(Constant.city, location.getCity());
        SharedPreferencesUtils.addgetSharedPreferences(Constant.pro, location.getProvince());
        SharedPreferencesUtils.addgetSharedPreferences(Constant.Longitude, location.getLongitude() + "");
        SharedPreferencesUtils.addgetSharedPreferences(Constant.Latitude, location.getLatitude() + "");
        Constant.city = location.getCity();
        latlng = new LatLng(location.getLatitude(), location.getLongitude());
        aMap.moveCamera(CameraUpdateFactory.changeLatLng(latlng));
        aMap.moveCamera(CameraUpdateFactory.zoomTo(14));
        if (!(SharedPreferencesUtils.getSharedPreferences(Constant.token, "") == null || SharedPreferencesUtils.getSharedPreferences(Constant.token, "").equals(""))) {
            agency(location.getProvince(), location.getCity());
        }
        LocationUtils.getInstance().stopLocation();
    }

    AdapterView.OnItemClickListener clickItem = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {
            // TODO Auto-generated method stub
            TableModle model = tabIndicators.get(arg2);
            if (SharedPreferencesUtil.getInstance().getString("members_id") == null || SharedPreferencesUtil.getInstance().getString("members_id").equals("")) {
                ToastUtil.toast(context, "非企业用户不能使用");
            } else {
                if (model.getId().equals("1")) {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE)
                            != PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(getActivity(), "没有权限,请手动开启定位权限", Toast.LENGTH_SHORT).show();
                        // 申请一个（或多个）权限，并提供用于回调返回的获取码（用户定义）

                    } else {
                        getActivity().startActivity(new Intent(getActivity(), DeviceMainTainActivity.class));
                    }
                } else if (model.getId().equals("2")) {
                    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)
                            != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_PHONE_STATE)
                            != PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(getActivity(), "没有权限,请手动开启定位权限", Toast.LENGTH_SHORT).show();
                        // 申请一个（或多个）权限，并提供用于回调返回的获取码（用户定义）

                    } else {
                        getActivity().startActivity(new Intent(getActivity(), DeviceRepairActivity.class));
                    }
                } else if (model.getId().equals("3")) {

                } else if (model.getId().equals("4")) {
                    Intent ktiIntent = null;
                    if (SharedPreferencesUtils.getSharedPreferences(Constant.ifadmin, "").equals("2")) {
                        ktiIntent = new Intent(getActivity(), MyToolkitActivity.class);
                    } else {
                        ktiIntent = new Intent(getActivity(), ToolkitActivity.class);
                    }
                    ktiIntent.putExtra("type", "1");
                    ktiIntent.putExtra("title", "" +
                            "工具箱");
                    startActivity(ktiIntent);
                } else if (model.getId().equals("5")) {
                    getActivity().startActivity(new Intent(getActivity(), CaptureActivity.class).putExtra("type", "2"));
                }
            }
        }

    };

}
